package com.business_clean.viewmodel.request

import androidx.lifecycle.MutableLiveData
import com.business_clean.app.config.Constant
import com.business_clean.app.network.NetUrl
import com.business_clean.data.mode.todo.TodoList
import me.hgj.mvvmhelper.base.BaseViewModel
import me.hgj.mvvmhelper.ext.rxHttpRequest
import me.hgj.mvvmhelper.net.LoadingType
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class TodoViewModel : BaseViewModel() {


    var todoList = MutableLiveData<TodoList>()

    var cancel = MutableLiveData<Any>()
    var reject = MutableLiveData<Any>()
    var agree = MutableLiveData<Any>()
    var del = MutableLiveData<Any>()

    /**
     * 获取列表
     */
    fun requestTodoList(page: Int, type: Int) {

        rxHttpRequest {
            onRequest = {
                todoList.value = RxHttp.get(NetUrl.GET_TODO_LIST)
                    .add("page", page)
                    .add("size", Constant.PAGE_SIZE)
                    .add("type", type)
                    .toResponse<TodoList>().await()
            }
            loadingType = LoadingType.LOADING_NULL
        }

    }

    /**
     * 取消
     */
    fun requestTodoCancel(application_no: String) {
        rxHttpRequest {
            onRequest = {
                cancel.value = RxHttp.get(NetUrl.TODO_CANCEL)
                    .add("application_no", application_no)
                    .toResponse<TodoList>().await()
            }
        }
    }

    /**
     * 同意
     */
    fun requestTodoAgree(application_no: String) {
        rxHttpRequest {
            onRequest = {
                agree.value = RxHttp.get(NetUrl.TODO_AGREE)
                    .add("application_no", application_no)
                    .toResponse<TodoList>().await()
            }
        }
    }

    /**
     * 拒绝
     */
    fun requestTodoReject(application_no: String) {
        rxHttpRequest {
            onRequest = {
                reject.value = RxHttp.get(NetUrl.TODO_REJECT)
                    .add("application_no", application_no)
                    .toResponse<TodoList>().await()
            }
        }
    }


    /**
     * 删除
     */
    fun requestDel(application_no: String) {
        rxHttpRequest {
            onRequest = {
                del.value = RxHttp.get(NetUrl.TODO_DELETE)
                    .add("application_no", application_no)
                    .toResponse<TodoList>().await()
            }
        }
    }
}